package cn.snmp.mutual.order;

import cn.snmp.mutual.nms.SnmpVarBind;
import lombok.extern.slf4j.Slf4j;

import cn.snmp.mutual.data.ObjService;

/**
 * @author dengkn
 * AbstractVarBindOrder 系统默认下发排序
 */
@Slf4j
public abstract class AbstractVarBindOrder {

    public static final String VARBIND_ORDER = "VarBindOrder";
    protected ObjService snmpCondition = null;
    protected ObjService mibTable = null;

    public void setSnmpCondition(ObjService snmpCondition) {
        this.snmpCondition = snmpCondition;
    }

    public void setMibTableInfo(ObjService mibTable) {
        this.mibTable = mibTable;
    }

    public static AbstractVarBindOrder getVarBindOrder(ObjService snmpParamObj, ObjService mibTable) {
        AbstractVarBindOrder order = null;

        try {
            String e = "";
            if (mibTable.objectSize(VARBIND_ORDER) > 0) {
                e = mibTable.objectAt(VARBIND_ORDER, 0).getStringValue("Class");
            }
            if ("".equals(e)) {
                order = null;
            } else {
                order = (AbstractVarBindOrder) Class.forName(e).newInstance();
                log.debug("Construct [" + e + "] successed...");
                order.setSnmpCondition(snmpParamObj);
                order.setMibTableInfo(mibTable);
            }
            return order;
        } catch (Exception e) {
            log.error("Varbind order exception", e);
            return order;
        }
    }

    public abstract SnmpVarBind[] order(SnmpVarBind[] arg0);
}